home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / util / cdity / yak158src.lha / Hotkey_Window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-08  |  16.0 KB  |  473 lines

  1.  
  2. /*
  3.  *  Source machine generated by GadToolsBox V2.0b
  4.  *  which is (c) Copyright 1991-1993 Jaba Development
  5.  *
  6.  *  GUI Designed by : Martin W Scott and GaĆ«l Marziou
  7.  */
  8.  
  9.  
  10.  
  11.  
  12. #include <exec/types.h>
  13. #include <intuition/intuition.h>
  14. #include <intuition/classes.h>
  15. #include <intuition/classusr.h>
  16. #include <intuition/imageclass.h>
  17. #include <intuition/gadgetclass.h>
  18. #include <intuition/intuitionbase.h>
  19. #include <libraries/gadtools.h>
  20. #include <graphics/displayinfo.h>
  21. #include <graphics/gfxbase.h>
  22. #include <proto/exec.h>
  23. #include <proto/intuition.h>
  24. #include <proto/gadtools.h>
  25. #include <proto/graphics.h>
  26. #include <proto/locale.h>
  27. #include <proto/utility.h>
  28. #include <string.h>
  29.  
  30.  
  31. #include "code.h"
  32. #include "version.h"
  33. #include "hotkey_types.h"
  34. #include "yak.h"
  35. #include "gui.h"
  36.  
  37. #define CATCOMP_NUMBERS
  38. #include "locale/yak_locale_strings.h"
  39.  
  40.  
  41. IMPORT struct Catalog    *Catalog;
  42.  
  43. extern LONG (*HandleIDCMP)(void);
  44.  
  45. struct Window   *HotKeyWnd = NULL;
  46. struct Gadget   *HotKeyGList = NULL;
  47. struct Gadget   *HotKeyGadgets[HotKey_CNT];
  48. UWORD            HotKeyLeft = 0;
  49. UWORD            HotKeyWidth = 530;
  50. UWORD            HotKeyHeight = 159;
  51. UBYTE           *HotKeyWdt = NULL;
  52.  
  53. WORD             HotkeysTop=0;
  54. WORD             ActionsTop=0;
  55.  
  56. UBYTE *Options1Labels[4];
  57.  
  58. VOID
  59. InitOptions1Label()
  60. {
  61.     Options1Labels[0] = getString(NO_SCREEN_CHANGE_STRING);
  62.     Options1Labels[1] = getString(WORKBENCH_TO_FRONT_STRING);
  63.     Options1Labels[2] = getString(DEFAULT_PUBSCR_TO_FRONT_STRING);
  64.     Options1Labels[3] = NULL;
  65. }
  66.  
  67.  
  68. IMPORT struct MinList Actions1List;
  69.  
  70. struct Node Actions1Nodes[] = 
  71. {
  72.     &Actions1Nodes[1] ,(struct Node *)&Actions1List.mlh_Head,0,0,NULL,
  73.     &Actions1Nodes[2] ,&Actions1Nodes[0] ,0,0,NULL,
  74.     &Actions1Nodes[3] ,&Actions1Nodes[1] ,0,0,NULL,
  75.     &Actions1Nodes[4] ,&Actions1Nodes[2] ,0,0,NULL,
  76.     &Actions1Nodes[5] ,&Actions1Nodes[3] ,0,0,NULL,
  77.     &Actions1Nodes[6] ,&Actions1Nodes[5] ,0,0,NULL,
  78.     &Actions1Nodes[7] ,&Actions1Nodes[6] ,0,0,NULL,
  79.     &Actions1Nodes[8] ,&Actions1Nodes[7] ,0,0,NULL,
  80.     &Actions1Nodes[9] ,&Actions1Nodes[8] ,0,0,NULL,
  81.     &Actions1Nodes[10],&Actions1Nodes[9] ,0,0,NULL,
  82.     &Actions1Nodes[11],&Actions1Nodes[10],0,0,NULL,
  83.     &Actions1Nodes[12],&Actions1Nodes[11],0,0,NULL,
  84.     &Actions1Nodes[13],&Actions1Nodes[12],0,0,NULL,
  85.     &Actions1Nodes[14],&Actions1Nodes[13],0,0,NULL,
  86.     &Actions1Nodes[15],&Actions1Nodes[14],0,0,NULL,
  87.     &Actions1Nodes[16],&Actions1Nodes[15],0,0,NULL,
  88.     (struct Node *)&Actions1List.mlh_Tail,&Actions1Nodes[15],0,0,NULL 
  89. };
  90.  
  91. VOID
  92. InitActions1Nodes()
  93. {
  94.     Actions1Nodes[0].ln_Name  = getString(DOS_Command_ACT);
  95.     Actions1Nodes[1].ln_Name  = getString(Close_Window_ACT);
  96.     Actions1Nodes[2].ln_Name  = getString(Zip_Window_ACT);
  97.     Actions1Nodes[3].ln_Name  = getString(Shrink_Window_ACT);
  98.     Actions1Nodes[4].ln_Name  = getString(Expand_Window_ACT);
  99.     Actions1Nodes[5].ln_Name  = getString(Cycle_Windows_ACT);
  100.     Actions1Nodes[6].ln_Name  = getString(Open_Palette_ACT);
  101.     Actions1Nodes[7].ln_Name  = getString(Screen_to_Front_ACT);
  102.     Actions1Nodes[8].ln_Name  = getString(Screen_to_Back_ACT);
  103.     Actions1Nodes[9].ln_Name  = getString(Activate_Workbench_ACT);
  104.     Actions1Nodes[10].ln_Name = getString(Centre_Screen_ACT);
  105.     Actions1Nodes[11].ln_Name = getString(Blank_Display_ACT);
  106.     Actions1Nodes[12].ln_Name = getString(Insert_Text_ACT);
  107.     Actions1Nodes[13].ln_Name = getString(Insert_Date_ACT);
  108.     Actions1Nodes[14].ln_Name = getString(Show_Yak_Interface_ACT);
  109.     Actions1Nodes[15].ln_Name = getString(Back_Cycle_Windows_ACT);
  110.     Actions1Nodes[16].ln_Name = getString(SetDefaultPublicScreen);
  111. }
  112.  
  113. struct MinList Actions1List = {
  114.     (struct MinNode *)&Actions1Nodes[0],
  115.     (struct MinNode *)NULL,
  116.     (struct MinNode *)&Actions1Nodes[14] };
  117.  
  118.  
  119. UWORD HotKeyGTypes[] = {
  120.         LISTVIEW_KIND,
  121.         LISTVIEW_KIND,
  122.         STRING_KIND,
  123.         CYCLE_KIND,
  124.         BUTTON_KIND,
  125.         BUTTON_KIND,
  126.         BUTTON_KIND
  127. };
  128.  
  129.  
  130. struct NewGadget HotKeyNGad[] = {
  131.         234,15,290,80,NULL,NULL,GD_Hotkeys  ,PLACETEXT_ABOVE|NG_HIGHLABEL,NULL,NULL,
  132.           6,15,224,96,NULL,NULL,GD_Actions  ,PLACETEXT_ABOVE|NG_HIGHLABEL,NULL,NULL,
  133.         234,109,290,14,NULL,NULL,GD_Argument,PLACETEXT_LEFT              ,NULL,NULL,
  134.         234,124,290,13,NULL,NULL,GD_Options ,PLACETEXT_LEFT              ,NULL,NULL,
  135.         234,93,110,13,NULL,NULL,GD_Add      ,PLACETEXT_IN                ,NULL,NULL,
  136.         414,93,110,13,NULL,NULL,GD_Delete   ,PLACETEXT_IN                ,NULL,NULL,
  137.         215,143,100,13,NULL,NULL,GD_Return  ,PLACETEXT_IN                ,NULL,NULL
  138. };
  139.  
  140. VOID InitHotKeyNGad (VOID)
  141. {
  142.     HotKeyNGad[GD_Hotkeys].ng_GadgetText  = getString(HOTKEYS_STRING);
  143.     HotKeyNGad[GD_Actions].ng_GadgetText  = getString(ACTIONS_STRING);
  144.     HotKeyNGad[GD_Argument].ng_GadgetText = getString(ARGUMENT_STRING);
  145.     HotKeyNGad[GD_Options].ng_GadgetText  = getString(OPTIONS_STRING);
  146.     HotKeyNGad[GD_Add].ng_GadgetText      = getString(ADD_STRING);
  147.     HotKeyNGad[GD_Delete].ng_GadgetText   = getString(DELETE_STRING);
  148.     HotKeyNGad[GD_Return].ng_GadgetText   = getString(OK_STRING);
  149. }
  150.  
  151.  
  152.  
  153. ULONG HotKeyGTags[] = {
  154.         (GTLV_ShowSelected),NULL,(TAG_DONE),
  155.         (GTLV_Labels),(ULONG)&Actions1List,(GTLV_ShowSelected),NULL,(TAG_DONE),
  156.         (GTST_MaxChars),512,(TAG_DONE),
  157.         (GTCY_Labels),(ULONG)&Options1Labels[ 0 ],(TAG_DONE),
  158.         (TAG_DONE),
  159.         (TAG_DONE),
  160.         (TAG_DONE)
  161. };
  162.  
  163.  
  164.  
  165.  
  166. VOID
  167. HotKeyRender()
  168. {
  169.         ComputeFont(HotKeyWidth,HotKeyHeight);
  170.  
  171.         DrawBevelBox(HotKeyWnd->RPort,OffX,
  172.                                         OffY +ComputeY(140),
  173.                                         ComputeX(530),
  174.                                         ComputeY(HotKeyHeight) -ComputeY(140),
  175.                                         GT_VisualInfo,VisualInfo,TAG_DONE);
  176.         DrawBevelBox(HotKeyWnd->RPort,OffX,
  177.                                         OffY,
  178.                                         ComputeX(530),
  179.                                         ComputeY(140),
  180.                                         GT_VisualInfo,VisualInfo,TAG_DONE);
  181. }
  182.  
  183.  
  184.  
  185.  
  186. int
  187. OpenHotKeyWindow()
  188. {
  189.         struct NewGadget        ng;
  190.         struct Gadget   *g;
  191.         UWORD           lc,tc;
  192.         UWORD           wleft = HotKeyLeft,wtop = WindowTop,ww,wh;
  193.  
  194.         ComputeFont(HotKeyWidth,HotKeyHeight);
  195.  
  196.         ww = ComputeX(HotKeyWidth);
  197.         wh = ComputeY(HotKeyHeight);
  198.  
  199.         if ((wleft +ww +OffX +Scr->WBorRight) > Scr->Width) wleft = Scr->Width -ww;
  200.         if ((wtop +wh +OffY +Scr->WBorBottom) > Scr->Height) wtop = Scr->Height -wh;
  201.  
  202.         if (! (g = CreateContext(&HotKeyGList)))
  203.                 return(1L);
  204.  
  205.         for(lc = 0,tc = 0; lc < HotKey_CNT; lc++) {
  206.  
  207.                 CopyMem((char *)&HotKeyNGad[ lc ],(char *)&ng,(long)sizeof(struct NewGadget));
  208.  
  209.                 ng.ng_VisualInfo = VisualInfo;
  210.                 ng.ng_TextAttr   = Font;
  211.                 ng.ng_LeftEdge   = OffX +ComputeX(ng.ng_LeftEdge);
  212.                 ng.ng_TopEdge    = OffY +ComputeY(ng.ng_TopEdge);
  213.                 ng.ng_Width      = ComputeX(ng.ng_Width);
  214.                 ng.ng_Height     = ComputeY(ng.ng_Height);
  215.  
  216.                 HotKeyGadgets[ lc ] = g = CreateGadgetA((ULONG)HotKeyGTypes[ lc ],g,&ng,(struct TagItem *)&HotKeyGTags[ tc ]);
  217.  
  218.                 while(HotKeyGTags[ tc ]) tc += 2;
  219.                 tc++;
  220.  
  221.                 if (NOT g)
  222.                         return(2L);
  223.         }
  224.  
  225.         if (! (HotKeyWnd = OpenWindowTags(NULL,
  226.                                 WA_Left,        wleft,
  227.                                 WA_Top,         wtop,
  228.                                 WA_Width,       ww +OffX +Scr->WBorRight,
  229.                                 WA_Height,      wh +OffY +Scr->WBorBottom,
  230.                                 WA_IDCMP,       LISTVIEWIDCMP|STRINGIDCMP|CYCLEIDCMP|BUTTONIDCMP|IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  231.                                 WA_Flags,       WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH,
  232.                                 WA_Gadgets,     HotKeyGList,
  233.                                 WA_Title,       HotKeyWdt,
  234.                                 WA_ScreenTitle,getString(COPYRIGHT_STRING),
  235.                                 WA_PubScreen,TRUE,
  236.                                 WA_PubScreenName,PubScreenName,
  237.                                 TAG_DONE)))
  238.         return(4L);
  239.  
  240.         GT_RefreshWindow(HotKeyWnd,NULL);
  241.  
  242.         HotKeyRender();
  243.  
  244.         return(0L);
  245. }
  246.  
  247.  
  248.  
  249.  
  250. VOID
  251. CloseHotKeyWindow()
  252. {
  253.         CloseOneWindow (HotKeyWnd,NULL,HotKeyGList);
  254.         HotKeyWnd = NULL;
  255. }
  256.  
  257.  
  258. /*******************************************************************************
  259.  *      HOTKEY SPECIFIC DATA/ROUTINES
  260.  *      perhaps move to another file?
  261.  *******************************************************************************/
  262.  
  263. /* prototypes */
  264. static struct Node *GetNode(struct List *lh, UWORD n);
  265. static UWORD GetNodeNum(struct List *lh, struct Node *node);
  266.  
  267. /* external data */
  268. YakHotKey       *curhk;
  269. UWORD           curtype;
  270.  
  271. /* get number of node in list - node MUST be there! */
  272. static UWORD
  273. GetNodeNum(struct List *lh, struct Node *node)
  274. {
  275.         struct Node *ln;
  276.         UWORD i;
  277.  
  278.         for (i = 0, ln = lh->lh_Head; ln != node; ln = ln->ln_Succ, i++)
  279.                 ;
  280.         return i;
  281. }
  282.  
  283. /* get nth node in list - list MUST have >= n nodes!!! */
  284. static struct Node *
  285. GetNode(struct List *lh, UWORD n)
  286. {
  287.         struct Node *ln;
  288.  
  289.         for (ln = lh->lh_Head; n--; ln = ln->ln_Succ)
  290.                 ;
  291.         return ln;
  292. }
  293.  
  294.  
  295.  
  296. /* initialise all gadgets of hotkey window */
  297. static void
  298. InitHotKeyGadgets(void)
  299. {
  300.         InitWindowGadget(GDX_Hotkeys, GTLV_Labels, (LONG)keylist(curtype), HOTKEY_WINDOW);
  301.         InitWindowGadget(GDX_Actions, GTLV_Selected, curtype, HOTKEY_WINDOW);
  302.  
  303.         InitWindowGadget(GDX_Delete, GA_Disabled, !curhk, HOTKEY_WINDOW);
  304.         /* something selected */
  305.         if (curhk)
  306.         {
  307.                 UWORD n = GetNodeNum(keylist(curtype), (struct Node *)curhk);
  308.  
  309.                 if (YHK_Has_Options(curhk))
  310.                 {
  311.                         InitWindowGadget(GDX_Options, GA_Disabled, FALSE, HOTKEY_WINDOW);
  312.                         InitWindowGadget(GDX_Options, GTCY_Active, (LONG)curhk->yhk_Options, HOTKEY_WINDOW);
  313.                 }
  314.                 else
  315.                         InitWindowGadget(GDX_Options, GA_Disabled, TRUE, HOTKEY_WINDOW);
  316.  
  317.  
  318.                 if (YHK_Takes_Arg(curhk))
  319.                 {
  320.                         InitWindowGadget(GDX_Argument, GA_Disabled, FALSE, HOTKEY_WINDOW);
  321.                         InitWindowGadget(GDX_Argument, GTST_String, (LONG)curhk->yhk_ArgStr, HOTKEY_WINDOW);
  322.                 }
  323.                 else
  324.                         InitWindowGadget(GDX_Argument, GA_Disabled, TRUE, HOTKEY_WINDOW);
  325.  
  326.                 InitWindowGadget(GDX_Actions, GTLV_Top,      curtype, HOTKEY_WINDOW);
  327.                 InitWindowGadget(GDX_Hotkeys, GTLV_Top     , n,       HOTKEY_WINDOW);
  328.                 InitWindowGadget(GDX_Hotkeys, GTLV_Selected, n,       HOTKEY_WINDOW);
  329.         }
  330.         else    /* no current hotkey */
  331.         {
  332.                 InitWindowGadget(GDX_Hotkeys, GTLV_Selected, -1, HOTKEY_WINDOW);
  333.  
  334.                 InitWindowGadget(GDX_Options, GTCY_Active, 0, HOTKEY_WINDOW);
  335.                 InitWindowGadget(GDX_Options, GA_Disabled, TRUE, HOTKEY_WINDOW);
  336.  
  337.                 InitWindowGadget(GDX_Argument, GTST_String, (LONG)"", HOTKEY_WINDOW);
  338.                 InitWindowGadget(GDX_Argument, GA_Disabled, TRUE, HOTKEY_WINDOW);
  339.         }
  340. }
  341.  
  342.  
  343. /* handle hotkey window events */
  344. LONG
  345. HandleHotKeyIDCMP(void)
  346. {
  347.     struct IntuiMessage *msg;
  348.     struct Gadget       *gadget;
  349.     ULONG               class;
  350.     UWORD               code;
  351.     static ULONG        savesec;
  352.     static ULONG        savemic;
  353.     static YakHotKey    *savehk;
  354.  
  355.  
  356.         while (msg = GT_GetIMsg(HotKeyWnd->UserPort))
  357.         {
  358.                 class = msg->Class;
  359.                 code = msg->Code;
  360.                 gadget = (struct Gadget *)msg->IAddress;
  361.                 GT_ReplyIMsg(msg);
  362.  
  363.                 switch (class)
  364.                 {
  365.                   case CLOSEWINDOW:
  366.                         HideInterface();
  367.                         return ROOT_OKAY;
  368.  
  369.                   case GADGETUP:
  370.                   case GADGETDOWN:
  371.                         switch (gadget->GadgetID)
  372.                         {
  373.                           case GD_Actions:
  374.                                 if (code != curtype)
  375.                                 {
  376.                                     curtype = code;
  377.                                     curhk   = NULL;
  378.  
  379.                                     InitHotKeyGadgets();
  380.                                 }
  381.                                 break;
  382.  
  383.                           case GD_Hotkeys:
  384.                                 curhk = (YakHotKey *)GetNode(keylist(curtype), code);
  385.                                 if (DoubleClick(savesec, savemic, msg->Seconds, msg->Micros) &&
  386.                                         (curhk == savehk) )
  387.                                 {
  388.                                     savehk  = NULL;
  389.                                     savemic = savesec = 0;
  390.  
  391.                                     if (SwitchToKeyDefWindow())
  392.                                         return ROOT_OKAY;
  393.                                     else
  394.                                         PostError(getString(Couldnt_open_other_window_ERR));
  395.                                 }
  396.                                 else
  397.                                 {
  398.                                     savesec = msg->Seconds;
  399.                                     savemic = msg->Micros;
  400.                                     savehk  = curhk;
  401.  
  402.                                     InitWindowGadget(GDX_Delete, GA_Disabled, !curhk, HOTKEY_WINDOW);
  403.                                     InitHotKeyGadgets();
  404.                                 }
  405.  
  406.                                 break;
  407.  
  408.                           case GD_Argument:
  409.                                 if (!curhk)             /* shouldn't happen */
  410.                                         break;
  411.                                 if (!(ModifyYHKArgStr(curhk, GetString(gadget))))
  412.                                         InitHotKeyGadgets();
  413.                                 break;
  414.  
  415.                           case GD_Options:
  416.                                 if (curhk)
  417.                                         curhk->yhk_Options = code;
  418.                                 break;
  419.  
  420.                           case GD_Add:
  421.                                 curhk = NewYakHotKey(curtype);
  422.                                 if (!SwitchToKeyDefWindow())
  423.                                         PostError(getString(Couldnt_open_other_window_ERR));
  424.                                 return ROOT_OKAY;
  425.  
  426.                           case GD_Delete:
  427.                                 if (curhk)
  428.                                 {
  429.                                         DeleteYakHotKey(curhk);
  430.                                         curhk = NULL;
  431.                                         InitHotKeyGadgets();
  432.                                 }
  433.                                 break;
  434.  
  435.                           case GD_Return:
  436.                                 curhk = NULL;   /* in case of reloading */
  437.                                 UpdateWindowsPosition();
  438.                                 CloseHotKeyWindow();
  439.                                 if (!ShowRootWindow())
  440.                                         PostError(getString(Couldnt_open_other_window_ERR));
  441.                                 return ROOT_OKAY;
  442.  
  443.                         }                                       /* switch (gadget->GadgetID) */
  444.                         break;
  445.  
  446.                   case REFRESHWINDOW:
  447.                         GT_BeginRefresh(HotKeyWnd);
  448.                         GT_EndRefresh(HotKeyWnd, TRUE);
  449.                         break;
  450.  
  451.                 }                                               /* switch (class) */
  452.  
  453.         } /* while more messages */
  454.  
  455.         return ROOT_OKAY;
  456. }
  457.  
  458. /* show our hotkey window */
  459. BOOL
  460. ShowHotKeyWindow(void)
  461. {
  462.         if (!OpenHotKeyWindow())        /* like the name says... */
  463.         {
  464.                 InitHotKeyGadgets();
  465.                 wndsigflag = 1 << HotKeyWnd->UserPort->mp_SigBit;
  466.                 curwin = HotKeyWnd;
  467.                 HandleIDCMP = HandleHotKeyIDCMP;
  468.                 return TRUE;
  469.         }
  470.         CloseDownScreen();
  471.         return FALSE;
  472. }
  473.